#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
string s, p;
int Next[N];
void build_next() {
  int t = -1;
  int i = 0;
  Next[0] = -1;
  while (i < n) {
    if (t < 0 || p[i] == p[t]) {
      i++, t++;
      Next[i] = t;
    } else {
      t = Next[t];
    }
  }
  rep(i, 1, n) {
    t = Next[i];
    while (Next[t] > 0) t = Next[t];
    Next[i] = t;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> p;
  build_next();
  ll sum = 0;
  rep(i, 1, n) if (Next[i] > 0 && Next[i] * 2 <= i) sum += i - Next[i];
  cout << sum;
  return 0;
}